#include "Map.h"

Map::Map():Transform()
{
	double x =0;
	double y = 0;

	//tige 1
	AutoRef<Tige> tige1(new Tige);
	tige1->setOrientation(true);
	double longueur = 1;
	tige1->setLongueur(longueur);
	this->children->push_back(tige1.get());
	tiges.push_back(tige1.get());
	x+=longueur/2;

	AutoRef<Bonus> bonus1(new Bonus);
	bonus1->setPosition(x-0.9,y-0.07);
	this->children->push_back(bonus1.get());
	bonus.push_back(bonus1.get());

	AutoRef<Piege> piege1(new Piege);
	piege1->setPosition(x-0.6,y+0.07);
	this->children->push_back(piege1.get());
	pieges.push_back(piege1.get());

	AutoRef<Bonus> bonus2(new Bonus);
	bonus2->setPosition(x-0.3,y+0.07);
	this->children->push_back(bonus2.get());
	bonus.push_back(bonus2.get());

	//tige2
	AutoRef<Tige> tige2(new Tige);
	tige2->setOrientation(false);
	longueur = 0.2;
	tige2->setLongueur(longueur);
	y -= longueur;
	tige2->setPosition(x,y/2);
	tige2->setDirection(-1);
	this->children->push_back(tige2.get());
	tiges.push_back(tige2.get());

	//tige 3
	AutoRef<Tige> tige3(new Tige);
	tige3->setOrientation(true);
	longueur = 0.6;
	tige3->setLongueur(longueur);
	x += longueur/2;
	tige3->setPosition(x,y);
	this->children->push_back(tige3.get());
	tiges.push_back(tige3.get());
	x+=longueur/2;

	//tige4
	AutoRef<Tige> tige4(new Tige);
	tige4->setOrientation(false);
	longueur = 0.15;
	tige4->setLongueur(longueur);
	y += (longueur+TIGE_RADIUS)/2;
	tige4->setPosition(x,y);
	tige4->setDirection(1);
	this->children->push_back(tige4.get());
	tiges.push_back(tige4.get());
	y += (longueur+TIGE_RADIUS)/2;

	AutoRef<Tige> tige5(new Tige);
	tige5->setOrientation(true);
	longueur = 1;
	tige5->setLongueur(longueur);
	x += longueur/2;
	tige5->setPosition(x,y);
	this->children->push_back(tige5.get());
	tiges.push_back(tige5.get());
	x+=longueur/2;

	AutoRef<Tige> tige6(new Tige);
	tige6->setOrientation(false);
	longueur = 0.25;
	tige6->setLongueur(longueur);
	y += (longueur+TIGE_RADIUS)/2;
	tige6->setPosition(x,y);
	tige6->setDirection(1);
	this->children->push_back(tige6.get());
	tiges.push_back(tige6.get());
	y += (longueur+TIGE_RADIUS)/2;

	AutoRef<Tige> tige7(new Tige);
	tige7->setOrientation(true);
	longueur = 0.5;
	tige7->setLongueur(longueur);
	x += longueur/2;
	tige7->setPosition(x,y);
	this->children->push_back(tige7.get());
	tiges.push_back(tige7.get());
	x+=longueur/2;

	AutoRef<Tige> tige8(new Tige);
	tige8->setOrientation(false);
	longueur = 0.3;
	tige8->setLongueur(longueur);
	y -= (longueur+TIGE_RADIUS)/2;
	tige8->setPosition(x,y);
	tige8->setDirection(-1);
	this->children->push_back(tige8.get());
	tiges.push_back(tige8.get());
	y -= (longueur+TIGE_RADIUS)/2;

	AutoRef<Tige> tige9(new Tige);
	tige9->setOrientation(true);
	longueur = 0.7;
	tige9->setLongueur(longueur);
	x += longueur/2;
	tige9->setPosition(x,y);
	this->children->push_back(tige9.get());
	tiges.push_back(tige9.get());
	x+=longueur/2;

	AutoRef<Tige> tige10(new Tige);
	tige10->setOrientation(false);
	longueur = 0.1;
	tige10->setLongueur(longueur);
	y += (longueur+TIGE_RADIUS)/2;
	tige10->setPosition(x,y);
	tige10->setDirection(1);
	this->children->push_back(tige10.get());
	tiges.push_back(tige10.get());
	y += (longueur+TIGE_RADIUS)/2;

	AutoRef<Tige> tige11(new Tige);
	tige11->setOrientation(true);
	longueur = 0.5;
	tige11->setLongueur(longueur);
	x += longueur/2;
	tige11->setPosition(x,y);
	this->children->push_back(tige11.get());
	tiges.push_back(tige11.get());
	x+=longueur/2;

	this->longueur=x+longueur/2-TIGE_RADIUS;

	this->translation->setValue(Vec3f(POS_MAP_DEPART,0,0));
}

vector<Tige*> Map::getTiges()
{
	return tiges;
}

vector<Bonus*> Map::getBonus()
{
	return bonus;
}

void Map::setBonus(vector<Bonus*> bonus)
{
	this->bonus = bonus;
}

vector<Piege*> Map::getPieges()
{
	return pieges;
}

void Map::setPieges(vector<Piege*> pieges)
{
	this->pieges = pieges;
}

double Map::getLongueur()
{
	return longueur;
}

void Map::nouveauJeu()
{
	vector<Bonus*> b;
	for(int j=0;j<bonus.size();j++)
	{
		bonus.at(j)->children->clear();
	}
	bonus.clear();
	for(int k=0;k<pieges.size();k++)
	{
		pieges.at(k)->children->clear();
	}
	pieges.clear();

	AutoRef<Bonus> bonus1(new Bonus);
	bonus1->setPosition(0.5-TIGE_RADIUS-0.9,-0.07);
	this->children->push_back(bonus1.get());
	bonus.push_back(bonus1.get());

	AutoRef<Piege> piege1(new Piege);
	piege1->setPosition(0.5-TIGE_RADIUS-0.6,0.07);
	this->children->push_back(piege1.get());
	pieges.push_back(piege1.get());

	AutoRef<Bonus> bonus2(new Bonus);
	bonus2->setPosition(0.5-TIGE_RADIUS-0.3,0.07);
	this->children->push_back(bonus2.get());
	bonus.push_back(bonus2.get());
}